package com.ld.caodan.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Adapter的基类
 * 
 * @author LD
 *
 * 下午04:17:36  2012-5-30
 */
public abstract class BaseAdapter<T> extends android.widget.BaseAdapter {

	Context context;
	List<T> list;
	LayoutInflater inflater;
	

	public BaseAdapter(Context context, List<T> list) {
		this.context = context;
		this.list = list;
		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public T getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if(v == null){
			v = newView();
		}
		bindDate2View(v,list.get(position));
		return  v;
	}
	
	public abstract View newView();
	
	public abstract void bindDate2View(View view,T t);

	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}
	
}
